#include <stdio.h>
#include <stdlib.h>
int* nextGreaterElement(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize) 
{
    *returnSize=nums1Size;
int *ans=(int*)malloc(sizeof(int)*nums1Size),i,j,k=0;
for(i=0;i<nums1Size;i++)
{
    int index,flag=0;
    for(j=0;j<nums2Size;j++)
    {
        if(nums2[j]==nums1[i])
        {
            index=j;
            break;
        }
    }
    for(j=index+1;j<nums2Size;j++)
    {
        if(nums2[j]>nums1[i])
        {
            flag=1;
            ans[k++]=nums2[j];
            break;
        }
    }
    if(flag==0)
        ans[k++]=-1;
}
return ans;

}



int main(int argc,char* argv[])
{
    int s1[]={2,4};
    int s2[]={1,2,3,4};
    int len1 = sizeof(s1)/4;
    int len2 = sizeof(s2)/4;
    int* res = nextGreaterElement(s1,len1,s2,len2,&len1);
    for(int i=0;i<sizeof(res)/4;i++)
    {
        printf("%d ",res[i]);
    }
    printf("\n");
    return 0;
}